package com.lkd.handler;


import com.lkd.business.MsgHandler;
import com.lkd.business.Topic;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VendoutContract;
import com.lkd.service.ChannelService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 出货消息处理器
 */
@Component
@Slf4j
@Topic(TopicConfig.VMS_VENDOUT_TOPIC)
public class VendoutMsgHandler implements MsgHandler {

    @Autowired
    private ChannelService channelService;

    @Override
    public void process(String jsonMsg) {
        log.info("接收到出货消息，jsonMsg={}",jsonMsg);
        if(StringUtils.isBlank(jsonMsg)){
            return ;
        }
        try {
            VendoutContract vendoutContract = JsonUtil.getByJson(jsonMsg, VendoutContract.class);
//        出货业务
            channelService.vendout(vendoutContract);
        }catch (Exception e){
            log.error("出货业务失败");
            e.printStackTrace();
        }
    }
}
